//
//  WYTextCell.m
//  Boss
//
//  Created by admin on 2018/7/5.
//  Copyright © 2018年 admin. All rights reserved.
//

#import "WYTextCell.h"
#import "YYText.h"
@interface WYTextCell()

@property (nonatomic,strong)YYLabel *label;

@end
@implementation WYTextCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self createSubViews];
    }
    return self;
    
}
-(void)createSubViews
{
    self.backgroundColor = [UIColor whiteColor];
    NSMutableAttributedString *text = [NSMutableAttributedString new];
    
    UIFont *font = [UIFont systemFontOfSize:16];
    //添加文本
    NSString *title =@"豫章故郡，洪都新府。星分翼轸，地接衡庐。襟三江而带五湖，控蛮荆而引瓯越。物华天宝，龙光射牛斗之墟；人杰地灵，徐孺下陈蕃之榻。雄州雾列，俊采星驰。台隍枕夷夏之交，宾主尽东南之美。都督阎公之雅望，棨戟遥临；宇文新州之懿范，襜帷暂驻。十旬休假，胜友如云；千里逢迎，高朋满座。腾蛟起凤，孟学士之词宗；紫电青霜，王将军之武库。家君作宰，路出名区；童子何知，躬逢胜饯。时维九月，序属三秋。潦水尽而寒潭清，烟光凝而暮山紫。俨骖騑于上路，访风景于崇阿。临帝子之长洲，得仙人之旧馆。层台耸翠，上出重霄；飞阁流丹，下临无地。鹤汀凫渚，穷岛屿之萦回；桂殿兰宫，列冈峦之体势。";
    
    [text appendAttributedString:[[NSAttributedString alloc] initWithString:title attributes:nil]];

    text.yy_font = font ;
    

    
    
    
    
    _label = [YYLabel new];
    //_label.backgroundColor = [UIColor redColor];
    [self addSubview:_label];
    [_label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.mas_equalTo(0);
        make.left.mas_equalTo(16);
        make.right.mas_equalTo(-16);
        make.height.mas_equalTo(100);
    }];
    _label.userInteractionEnabled =YES;
    
    _label.numberOfLines =0;
    
    _label.textVerticalAlignment =YYTextVerticalAlignmentTop;
    
     _label.attributedText = text;
    
    [self addSeeMoreButton];

}
- (void)addSeeMoreButton
{
    
    NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:@"...more"];
    YYTextHighlight *hi = [YYTextHighlight new];
    [hi setColor:[UIColor colorWithRed:0.578 green:0.790 blue:1.000 alpha:1.000]];
    hi.tapAction = ^(UIView *containerView,NSAttributedString *text,NSRange range, CGRect rect) {
        YYLabel *label = self.label;
        [label sizeToFit];
        
    };
    
    
    
    [text yy_setColor:[UIColor colorWithRed:0.000 green:0.449 blue:1.000 alpha:1.000]range:[text.string rangeOfString:@"more"]];
    
    [text yy_setTextHighlight:hi range:[text.string rangeOfString:@"more"]];
    
    text.yy_font =_label.font;
    
    
    
    YYLabel *seeMore = [YYLabel new];
    
    seeMore.attributedText = text;
    
    [seeMore sizeToFit];
    
    
    
    NSAttributedString *truncationToken = [NSAttributedString yy_attachmentStringWithContent:seeMore contentMode:UIViewContentModeCenter attachmentSize:seeMore.frame.size alignToFont:text.yy_font alignment:YYTextVerticalAlignmentCenter];
    
    _label.truncationToken = truncationToken;
}
@end
